---
title: "Table A.3"
output: 
---

# Table A.3

# Who's to Blame? Postconflict Violence and Public Attitudes Towards Peace Agreements
# Wyer, Frank. 

#clear environment
```{r clear environment}
rm(list = ls())
```

# uncomment and set working directory to replication archive
# setwd("~/blame_replication")

# Uncomment to install packages if necessary
# install.packages("tidyverse")
# install.packages("texreg")
# install.packages("estimatr")


#load packages
```{r}
library(tidyverse)
library(estimatr)
library(texreg)
```

#read in data
```{r}
survey_clean <- read.csv("survey_clean.csv")
```

#create blame gap variable
#difference between confidence in government implementation and rebel compliance
```{r blame gap variable}
survey_clean <- survey_clean %>% mutate(blame_gap = Q45 - Q46)
```

#scale mechanism variables
```{r scale mechanism variables}
survey_clean$govconf_scale <- (survey_clean$Q45 - mean(survey_clean$Q45[survey_clean$treatment == "C"], na.rm = TRUE)) / sd(survey_clean$Q45[survey_clean$treatment == "C"], na.rm = TRUE)

survey_clean$farcconf_scale <- (survey_clean$Q46 - mean(survey_clean$Q46[survey_clean$treatment == "C"], na.rm = TRUE)) / sd(survey_clean$Q46[survey_clean$treatment == "C"], na.rm = TRUE)

survey_clean$blamegap_scale <- (survey_clean$blame_gap - mean(survey_clean$blame_gap[survey_clean$treatment == "C"], na.rm = TRUE)) / sd(survey_clean$blame_gap[survey_clean$treatment == "C"], na.rm = TRUE)
```

#estimate mechanism models in control group
```{r estimate mechanisms in control}
implement_mech_control <- lm_robust(formula = outcomes_zscale ~ govconf_scale, se_type = "HC2", data = survey_clean %>% filter(treatment == "C"), alpha = .05)

comply_mech_control <- lm_robust(formula = outcomes_zscale ~ farcconf_scale, se_type = "HC2", data = survey_clean %>% filter(treatment == "C"), alpha = .05)

difference_mech_control <- lm_robust(formula = outcomes_zscale ~ blamegap_scale, se_type = "HC2", data = survey_clean %>% filter(treatment == "C"), alpha = .05)
```

#collect t-statistics
```{r collect t-statistics for main variable in each model}
tstat_gof <- list("T-Statistic" = c(implement_mech_control[["statistic"]][["govconf_scale"]], comply_mech_control[["statistic"]][["farcconf_scale"]], difference_mech_control[["statistic"]][["blamegap_scale"]]))
```

#generate table using texreg
```{r generate table}
texreg(list(implement_mech_control, comply_mech_control, difference_mech_control), custom.coef.map = list("govconf_scale" = "Confidence in Government Implementation", "farcconf_scale" = "Confidence in FARC Compliance", "blamegap_scale" = "Confidence Gap"), digits = 2, include.ci = FALSE, single.row = FALSE, include.fstatistic = FALSE, include.rmse = FALSE, include.rsquared = FALSE, include.adjrs = FALSE, include.nobs = TRUE, custom.gof.rows = tstat_gof, stars = numeric(0), float.pos = "h", caption.above	= TRUE, caption = "Relationship Between Mechanisms and Peace Agreement Attitudes in Control")
```